<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="../js/jquery-3.1.1.js" type="text/javascript"></script>
<script src="../bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">


<script type="text/javascript">
	// 监听所有input
	$(document).keypress(function(e) {
		if (e.which == 13) {
			addDormitory();
		}
	});

	// 用户登陆
	function addDormitory() {
		var zoom1 = $('#zoom1').val();
		var zoom2 = $("#zoom2").val();
		var zoom3 = $("#zoom3").val();
		var counselor_id = $("#counselor_id").val();
		var not_null = true;
		$("input[type='text']").each(function() {
			if ($(this).val() == "") {
				not_null = false;
			}
		});
		if (not_null == true) {
			$.ajax({
				url : 'http://localhost:8080/Hello/dormitory/add_dormitory.do',
				type : 'post',
				data : {
					"zoom1" : zoom1,
					"zoom2" : zoom2,
					"zoom3" : zoom3,
					"counselor_id" : counselor_id
				},
				dataType : 'json',
				success : function(data) {
					if (data.result == "success") {
						$('#zoom1').val("");
						$('#zoom2').val("");
						$('#zoom3').val("");
						$('#counselor_id').val("");
						$("#result_div").show();
						$("#result_div").attr("class", "alert alert-success");
						$("#result_div").text(data.result);
					} else {
						$("#result_div").show();
						$("#result_div").attr("class", "alert alert-danger");
						$("#result_div").text(data.result);
					}
				},
				error : function(data) {
					console.log("网络错误");
				}
			})
		} else {
			$("#result_div").show();
			$("#result_div").attr("class", "alert alert-warning");
			$("#result_div").text("寝室数据不能为空");
		}
	}
</script>
<title>添加寝室</title>
</head>
<body>
	<div class="container-fluid">
		<div class="row" style="margin-top: 10px">
			<div class="col-md-3" style="margin-top: 10px">
				<div class="input-group">
					<span class="input-group-addon">生活区名称</span>
					<input type="text" class="form-control" placeholder="生活区名称" id="zoom1">
				</div>
			</div>
			<div class="col-md-3" style="margin-top: 10px">
				<div class="input-group">
					<span class="input-group-addon">寝室楼号</span>
					<input type="text" class="form-control" placeholder="寝室楼号" id="zoom2">
				</div>
			</div>
			<div class="col-md-3" style="margin-top: 10px">
				<div class="input-group">
					<span class="input-group-addon">寝室号</span>
					<input type="text" class="form-control" placeholder="寝室号" id="zoom3">
				</div>
			</div>
			<div class="col-md-3" style="margin-top: 10px">
				<div class="input-group">
					<span class="input-group-addon">宿管员</span>
					<input type="text" class="form-control" placeholder="宿管员编号" id="counselor_id">
				</div>
			</div>
		</div>
		<div class="row" style="margin-top: 10px">
			<div class="col-md-2" style="margin-top: 10px"></div>
			<div class="col-md-3" style="margin-top: 10px">
				<div class="" role="alert" id="result_div"></div>
			</div>
			<div class="col-md-2" style="margin-top: 10px">
				<button class="btn btn-success" onclick="addDormitory()">添加寝室</button>
			</div>
			<div class="col-md-5" style="margin-top: 10px"></div>
		</div>
	</div>


</body>
</html>